/**
 * 从1出发，每秒移动一格
 * 有的格子优先级，在指定时间触发，一旦触发就不能再通过
 * 问最远能移动到多远且能安全返回1
 * 枚举一下即可
 */
#include <bits/stdc++.h>
using namespace std;

#include <bits/extc++.h>
using namespace __gnu_pbds;

using Real = long double;
using llt = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#ifndef ONLINE_JUDGE
int const SZ = 101;
#else
int const SZ = 110;
#endif

int N;
map<int, int> M;

int proc(int now, int limit){
	return (limit - now + 1 >> 1) - 1;
}

int proc(){
	int ans = 0x7F8F9FAF;
    for(const auto & p : M){
		int t = p.first - 1;
		int bong = t + p.second;
        ans = min(ans, proc(t, bong) + p.first);
	}
	return ans;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int nofkase; cin >> nofkase;
	while(nofkase--){
        cin >> N;
		M.clear();
		for(int s,d,i=0;i<N;++i){
			cin >> d >> s;
			auto it = M.find(d);
			if(it == M.end()) it = M.insert(it, {d, s});
			if(s < it->second) it->second = s;
		}
		cout << proc() << endl;
	}
    return 0;
}